package com.yidu.hbatsft.action;

import com.yidu.hbatsft.domain.AtsRival;
import com.yidu.hbatsft.domain.AtsRivalResult;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RivalWordAddData {


    public XWPFDocument exportWord(Object object, List<AtsRivalResult> one, int count){
        RivalExportWord ew = new RivalExportWord(count);
        XWPFDocument document = ew.createXWPFDocument();
        List<List<Object>> list = new ArrayList<List<Object>>();
        Map<String, Object> dataList = null;
        AtsRival atsRival = (AtsRival) object;
        List<Object> tempList = new ArrayList<Object>();
        tempList.add("对手姓名");
        tempList.add(atsRival.getRivName());
        tempList.add("性别");
        tempList.add(atsRival.getRivSex());
        tempList.add("运动项目");
        tempList.add(atsRival.getSportName());
        list.add(tempList);

        tempList = new ArrayList<Object>();
        tempList.add("缺点");
        tempList.add(atsRival.getRivFailing());
        list.add(tempList);

        tempList = new ArrayList<Object>();
        tempList.add("技术风格");
        tempList.add(atsRival.getRivTechnique());
        list.add(tempList);

        tempList = new ArrayList<Object>();
        tempList.add("战术风格");
        tempList.add(atsRival.getRivTactics());
        list.add(tempList);

        tempList = new ArrayList<Object>();
        tempList.add("应对方案");
        tempList.add(atsRival.getRividea());
        list.add(tempList);

        tempList = new ArrayList<Object>();
        tempList.add("导出人");
        tempList.add(atsRival.getCreater());
        tempList.add("");
        tempList.add("导出时间");
        tempList.add(atsRival.getCreatTime());
        list.add(tempList);


        if(count>0){
            for (int i =0;i<one.size();i++){
                tempList = new ArrayList<Object>();
                tempList.add("比赛成绩");
                list.add(tempList);

                tempList = new ArrayList<Object>();
                tempList.add("比赛名称");
                tempList.add(one.get(i).getMatchName());
                tempList.add("");
                tempList.add("比赛项目");
                tempList.add(one.get(i).getMatchItem());
                list.add(tempList);

                tempList = new ArrayList<Object>();
                tempList.add("比赛成绩");
                tempList.add(one.get(i).getMatchResult());
                tempList.add("");
                tempList.add("比赛排名");
                tempList.add(one.get(i).getMatchSort());
                list.add(tempList);

                tempList = new ArrayList<Object>();
                tempList.add("积分");
                tempList.add(one.get(i).getScore());
                tempList.add("比赛地点");
                tempList.add(one.get(i).getMatchAddr());
                tempList.add("比赛时间");
                tempList.add(one.get(i).getMatchTime());
                list.add(tempList);
            }

        }

        dataList = new HashMap<String, Object>();
        dataList.put("TITLE", "对手信息");
        dataList.put("TABLEDATA", list);
        try {
            ew.exportCheckWord(dataList, document);
            return document;
        } catch (IOException e) {
            e.printStackTrace();
            return  null;
        }

    }
}
